class_name AbilitySystem extends Node

"""
能力组件，每个敌我单位身上都要有一个，用于控制父类属性和管理效果
，通过添加Ability来实现效果的控制
"""
"
自定义effect，伤害的处理
"
@export var attribute:Attribute#父类的所有属性
@export var hurm_handle:HarmHandle#用于伤害的处理
#@export var tag:Array[String] = []#父类标签

var ability_list:Array[Ability] = []#储存所有能力的数组
var effect_list:Array[Effect]= []#储存所有效果的数组

func _ready() -> void:
	if hurm_handle:
		hurm_handle.item = self.get_parent()
	pass

#添加cue特效
func add_cue(cue:Cue) -> void:
	self.get_parent().add_child(cue)
	pass

"ability"
# 给能力组件添加新能力并绑定能力结束的信号
func add_ability(_ability:Ability) -> void:
	_ability.AS = self
	self.ability_list.append(_ability)
	_ability.end_ability.connect(_on_Ability_end_ability.bind(_ability))
	pass

# 执行某一能力
func activate_abilities(_ab:Ability) -> void:
	for ability in self.ability_list:
		if ability == _ab:
			ability.activate_ability()
	pass
	
# 执行所有能力
func activate_all_abilities() -> void:
	for ability in self.ability_list:
		ability.activate_ability()
	pass

# 查找某一能力
func find_ability(_ab:Ability) -> bool:
	for ability in self.ability_list:
		if ability == _ab:
			return true
	return false

# 技能销毁时从数组中删除
func _on_Ability_end_ability(_ability:Ability) -> void:
	self.ability_list.erase(_ability)
	pass
"ability"

"effect"
# 添加效果
func add_effect(effect:Effect) -> void:
	effect.in_effect(self)
	self.effect_list.append(effect)
	effect.effect_end.connect(on_effect_end.bind(effect))
	pass
#效果消失时
func on_effect_end(effect:Effect) -> void:
	self.effect_list.erase(effect)
	pass
"effect"

"attribute"
func get_speed() -> float:
	return attribute.最终速度
func get_hp() -> int:
	return self.attribute.血量
func set_max_hp(max_hp:int) -> void:
	self.attribute.最大血量 = max_hp
	pass
func set_hp(hp:int) -> void:
	self.attribute.血量 = hp
	pass
func set_speed(speed:int) -> void:
	self.attribute.移动速度 = speed
	pass
func change_hp(num:int,type:String = "") -> void:
	self.attribute.血量 += hurm_handle.handle_harm(num,type)
	
	pass
"attribute"
